package com.example.mutildatasource;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;

import javax.annotation.Resource;

@EnableTransactionManagement
@SpringBootApplication
//@MapperScan("com.example.*.mapper")
public class SpringbootMybatisMutilDatasourceApplication implements TransactionManagementConfigurer {

	@Resource(name="primaryTransactionManager")
	private PlatformTransactionManager primaryTransactionManager;

	public static void main(String[] args) {
		SpringApplication.run(SpringbootMybatisMutilDatasourceApplication.class, args);
	}

	/**
	 * 系统默认事务管理器
	 * @return
	 */
	@Override
	public PlatformTransactionManager annotationDrivenTransactionManager() {
		return primaryTransactionManager;
	}

	/**
	 * 打印Spring容器初始化的Bean
	 * @param args
	 */
	public static void printBean(String[] args){
		ApplicationContext ctx = SpringApplication.run(SpringbootMybatisMutilDatasourceApplication.class, args);
		String[] beanNames =  ctx.getBeanDefinitionNames();
//		String[] beanNames =  ctx.getBeanNamesForAnnotation(Service.class);//打印@Service注解的Bean
		System.out.println("beanNames个数："+beanNames.length);
		for(String bn:beanNames){
			System.out.println(bn);
		}
	}

}
